import { NestModule, MiddlewareConsumer, Module, Global } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserActivityLoggerMiddleware } from '../../middlewares/user-activity-logger.middleware';
import { OrganizationAdminController } from './controllers/admin/organization.admin.controller';
import { OrganizationEntity } from './entities/organization.entity';
import { OrganizationService } from './services/organization.service';

@Global()
@Module({
  imports: [PassportModule.register({ defaultStrategy: 'bearer' }), TypeOrmModule.forFeature([OrganizationEntity])],
  controllers: [OrganizationAdminController],
  providers: [OrganizationService],
  exports: [PassportModule.register({ defaultStrategy: 'bearer' }), OrganizationService]
})
export class OrganizationModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(UserActivityLoggerMiddleware).forRoutes(OrganizationAdminController);
  }
}
